function [err,pM,pS,pS_2w,pi,V,Vtp1] = ex_ante_mom(states,xadata,fixedparms,spec,alpha) 
 % log likelihood for belief estimation

 % assign parameter values
    %---------------
    beliefparms.sigma_ea=alpha(1); % alpha(1); 

    % belief coeficients
    i=3;
    j=i+fixedparms.n_beliefparms-1;  
    
    beliefparms.theta=alpha(i:j);
    i=j+1;
    beliefparms.gamma=alpha(i);
    i=i+1;
    beliefparms.gamma_mod=alpha(2); % only for robustness
    
    % VTp1 -- start terminal values
    beliefparms.VTp1=alpha(i);
    i=i+1;
    beliefparms.V0=alpha(i);
    
    i=i+1;
    beliefparms.sh_inattentive=alpha(i) ; 


   [pM,pS,pS_2w,pi,V,Vtp1] = solve_problem(states,fixedparms,xadata,spec,beliefparms);

   
% assign probabilities to individual observations 
%--------------------------------------
prM=NaN(size(xadata.G_exante(:,1),1),1);
prS=NaN(size(xadata.G_exante(:,1),1),1);
  
% two way choices 
for a=13:22
    emax=min(a-6,13);
    for e=[7:emax ]
        prM(xadata.age==a & xadata.ed==e & xadata.stillinschool==0 & xadata.G_exante(:,1)==0 )= ...
                pM(states(:,1)==a & states(:,2)==e & states(:,3)~=1 ,1);
        
        prM(xadata.age==a & xadata.ed==e & xadata.stillinschool==0 & xadata.G_exante(:,1)==1 )= ...
                pM(states(:,1)==a & states(:,2)==e & states(:,3)~=1 ,2);  
        
     end
end

% while still in school 
for a=13:22
        prM(xadata.age==a &  xadata.stillinschool==1 & xadata.G_exante(:,1)==0 )= ...
                pM(states(:,1)==a &  states(:,3)==1 ,1);
        
        prM(xadata.age==a &  xadata.stillinschool==1 & xadata.G_exante(:,1)==1 )= ...
                pM(states(:,1)==a &  states(:,3)==1 ,2);   
            
       prS(xadata.age==a &  xadata.stillinschool==1 & xadata.G_exante(:,1)==0 )= ...
                pS(states(:,1)==a &  states(:,3)==1 ,1);
        
       prS(xadata.age==a &  xadata.stillinschool==1 & xadata.G_exante(:,1)==1 )= ...
                pS(states(:,1)==a &  states(:,3)==1 ,2); 
    
end


prH=NaN(size(prM));
prH(xadata.stillinschool==0)=1-prM(xadata.stillinschool==0);
prH(xadata.stillinschool==1)=1-prM(xadata.stillinschool==1)-prS(xadata.stillinschool==1);

l=zeros(size(xadata.G_exante(:,1)))';

% inattention - 2 way choices
 prM(xadata.stillinschool==0)=prM(xadata.stillinschool==0).*(1-beliefparms.sh_inattentive)+beliefparms.sh_inattentive/2;
 prH(xadata.stillinschool==0)=prH(xadata.stillinschool==0).*(1-beliefparms.sh_inattentive)+beliefparms.sh_inattentive/2;

 prM(xadata.stillinschool==1)=prM(xadata.stillinschool==1).*(1-beliefparms.sh_inattentive)+beliefparms.sh_inattentive/3;
 prH(xadata.stillinschool==1)=prH(xadata.stillinschool==1).*(1-beliefparms.sh_inattentive)+beliefparms.sh_inattentive/3;
 prS(xadata.stillinschool==1)=prS(xadata.stillinschool==1).*(1-beliefparms.sh_inattentive)+beliefparms.sh_inattentive/3;

% set bounds so objective function always defined
prM=max(prM,0.001);
prS(prS~=NaN)=max(prS(prS~=NaN),0.001);
prH=max(prH,0.001);

l(xadata.chosen_marry==1)=log(prM(xadata.chosen_marry==1));
l(xadata.chosen_school==1)=log(prS(xadata.chosen_school==1));
l(xadata.chosen_marry==0 & xadata.chosen_school==0)=log(prH(xadata.chosen_marry==0 & xadata.chosen_school==0));
l=l.*xadata.w';

% add penalty to set constraint that there is always positive mass in all
% cells
penalty=(pi<0.0001); 

err=-sum(l,2)+1000.*(sum(sum(penalty,1),2)>0); 

end